package com.church.daoimpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.church.dao.QandaDao;
import com.church.db.Qanda;

public class QandaDaoImpl extends HibernateDaoSupport implements QandaDao {

	@Override
	public List<Qanda> getList(String object) {
		List<Qanda> list = this.getHibernateTemplate().find("from Qanda as qa where qa.subject='"+object+"' and state!='3'");
		return list;
	}

	@Override
	public String add(Qanda qanda) {
		this.getHibernateTemplate().save(qanda);
		return "success";
	}

	@Override
	public String remove(Qanda qanda) {
		this.getHibernateTemplate().delete(qanda);
		return "success";
	}

	@Override
	public String update(Qanda qanda) {
		this.getHibernateTemplate().persist(qanda);
		return "success";
	}

	@Override
	public Qanda findById(long id) {
		List<Qanda> list = this.getHibernateTemplate().find("from Qanda as qa where qa.id="+id);
		if(list.size()>0)
		{
			return list.get(0);
		}
		return null;
	}

}
